package com.yoomiito.app.present.my.fragment;


import com.yoomiito.app.Constant;
import com.yoomiito.app.model.my.MyHistoryMonthInfo;
import com.yoomiito.app.net.YmApi;
import com.yoomiito.app.ui.fragment.my.MyHistoryMonthFragment;
import com.yoomiito.app.utils.NetworkUtils;
import com.yoomiito.app.utils.YMToast;

import cn.droidlover.xdroidmvp.mvp.XPresent;
import cn.droidlover.xdroidmvp.net.ApiException;
import cn.droidlover.xdroidmvp.net.ApiSubscriber;
import cn.droidlover.xdroidmvp.net.XApi;

public class MyHistoryMonthFmPresenter extends XPresent<MyHistoryMonthFragment> {
    public void getHistoryMonthData(int page,int month){
        if (NetworkUtils.checkNetPermission(getV().getContext())){
            return;
        }
        YmApi.getYmService()
                .getHistoryMonth(page,month,Constant.PAGE_SIZE)
                .compose(getV().bindToLifecycle())
                .compose(XApi.<MyHistoryMonthInfo>getApiTransformerData())
                .compose(XApi.<MyHistoryMonthInfo>getScheduler())
                .subscribe(new ApiSubscriber<MyHistoryMonthInfo>() {
                    @Override
                    public void onSuccess(MyHistoryMonthInfo dataList) {
                        getV().setHistoryMonthData(dataList);
                    }

                    @Override
                    public void onFail(ApiException error) {
                        YMToast.showText("error");
                    }
                });
    }
}
